package com.gopay.bis.ccb.ebank.impl;

import com.gopay.bis.ccb.ebank.operation.B2bSocketTransportImpl;
import com.gopay.bis.ccb.ebank.operation.CcbB2bBuildMessage;
import com.gopay.bis.ccb.ebank.operation.CcbB2bParseMessage;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.ccb.ebank.pay.CcbB2bMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.BankService;

/**
 * 建行B2B请求接口
 * 
 * @CcbB2bBankServiceImpl.java
 * @author WangHongFei
 */
public class CcbB2bBankServiceImpl implements BankService {
	private B2bSocketTransportImpl b2bSocketTransportImpl;
	private CcbB2bBuildMessage ccbB2bBuildMessage;
	private CcbB2bParseMessage ccbB2bParseMessage;
    private ICertHelper ccbB2bCerthelper;

    /**
     * 签名
     * 
     * @param BaseMessage
     * @return String
     */
    public String sign(BaseMessage message) throws GopayException{
        String signMsg = "";
        signMsg = ccbB2bCerthelper.sign(message);
        return signMsg;
    }

    /**
     * 验签
     * 
     * @param BaseMessage
     * @return Object
     */
    public Object verify(BaseMessage message) throws GopayException{    	
        boolean verifyResult = false;
        verifyResult = (Boolean) ccbB2bCerthelper.verify(message);
        return verifyResult;

    }

    /**
     * 订单查询
     * 
     * @param Object
     * @return Object
     */
    public Object query(Object object) throws GopayException{
    	 CcbB2bMessage ccbB2bMessage = (CcbB2bMessage) object;
         String bulidMsg = ccbB2bBuildMessage.buildB2bXmlStr(ccbB2bMessage);// 构建xml
         Object obj = this.b2bSocketTransportImpl.submit(bulidMsg); // 发送银行
         CcbB2bMessage retMsg = ccbB2bParseMessage.parseB2bXml(obj);// 解析银行返回参数
         return retMsg;
    }

	public void setB2bSocketTransportImpl(
			B2bSocketTransportImpl b2bSocketTransportImpl) {
		this.b2bSocketTransportImpl = b2bSocketTransportImpl;
	}

	public void setCcbB2bBuildMessage(CcbB2bBuildMessage ccbB2bBuildMessage) {
		this.ccbB2bBuildMessage = ccbB2bBuildMessage;
	}

	public void setCcbB2bParseMessage(CcbB2bParseMessage ccbB2bParseMessage) {
		this.ccbB2bParseMessage = ccbB2bParseMessage;
	}

	public void setCcbB2bCerthelper(ICertHelper ccbB2bCerthelper) {
		this.ccbB2bCerthelper = ccbB2bCerthelper;
	}

	@Override
	public Object dayend(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object refund(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

}
